<style type="text/css">
    table {
        max-width: 750px;
    }

    .content-textbox {
        max-height: 20em;
        overflow: auto;
    }

    .content-title {
    }
</style>
<div id="berita-dialog" title="Highlight Berita" style="display: none;">
    <input type="hidden" class="id" />
    <h1 class="judul title content-title">Judul Berita</h1>
    <p>
        <span class="keterangan"></span>
    </p>
    <p class="content-textbox">
        <span class="sum">
        </span>
    </p>
</div>
<div style="margin-top: 2em; margin-bottom: 2em; display: block;">
    <?php $this->view("artikel/berita/hlberita"); ?>
</div>
<div>
    <h1 class="title">Daftar Berita</h1>

    <table id="listberita" style="margin-top: 1em;">
        <thead>
            <tr>
                <th>Judul Berita</th>
                <th>Penulis</th>
                <th>Aksi</th>
            </tr>
        </thead>
        <tbody>
            <?php
            if (count($artikelList) > 0) {
                foreach ($artikelList as $berita) {
                    echo "<tr>";
                    echo "<td>" . $berita->content_id->title . "</td>";
                    echo "<td>" . $berita->content_id->poster_id->display_name . "</td>";
                    echo "<td>" . "<a href='javascript:void(0);' onClick='javascript:showDialog(" . $berita->id . ");'>Pilih</a>" . "</td>";
                    echo "</tr>";
                }
            } else {
                echo "<tr>";
                echo "<td style='text-align: center;' colspan='3'>" . "(tidak ada entry berita menunggu approval)" . "</td>";
                echo "</tr>";
            }
            ?>
        </tbody>
    </table>
</div>
<script type="text/javascript">
            jQuery(document).ready(function() {
                $("#berita-dialog").dialog({
                    modal: true,
                    autoOpen: false,
                    width: "53em",
                    resizeable: false,
                    buttons: {
                        "Batal": function() {
                            $(this).dialog("close");
                        },
                        "Pilih": function() {
                            if (confirm("Pilih berita sebagai HIGLIGHT?")) {
                                $.ajax({
                                    type: "POST",
                                    url: "<?php echo site_url("artikel/saveHLArtikel"); ?>",
                                    async: false,
                                    data: {
                                        id: $("#berita-dialog .id").val()
                                    },
                                    beforeSend: function(xhr) {
                                    },
                                    success: function(result, status, xhr) {
                                        window.location = "<?php echo site_url("usercp/hlartikel/b"); ?>";
                                    },
                                    error: function(xhr, status, error) {
                                        window.location = "<?php echo site_url("usercp/hlartikel/b"); ?>";
                                    }
                                });
                            }
                        }
                    }
                });
            });

            function showDialog(Id) {
                $.ajax({
                    url: "<?php echo site_url("service/getDataJSON/brtbyid"); ?>",
                    method: "POST",
                    dataType: "json",
                    data: {
                        id: Id
                    },
                    success: function(berita) {
                        $("#berita-dialog .judul").text(berita.content_id.title);
                        $("#berita-dialog .content-textbox .sum").html(berita.content_id.text);
                        $("#berita-dialog .id").val(berita.id);
                    }
                });

                $("#berita-dialog").dialog("open");
            }
</script>